package com.kuaimacode.kframework.api.util;

import org.apache.commons.lang3.StringUtils;

/**
 * @author qinyong
 * @Title:
 * @Package com.kuaimacode.kframework.api.util
 * @Description: created by IntelliJ IDEA
 * @date 2019-04-12 11:38
 */
public class MaskUtil {

    /**
     * 掩码身份证号
     * @param idCard
     * @return
     */
    public static String maskIdCard(String idCard) {
        if (StringUtils.isBlank(idCard) || idCard.length() != 18) {
            return idCard;
        }

        String v = idCard.substring(0, 4);
        String end = idCard.substring(idCard.length() - 4);
        return v + StringUtils.repeat("*", 8) + end;
    }

    public static String interceptBack(String content, int number) {
        return content.substring(content.length() - number);
    }

    public static String interceptBack4(String content) {
        return interceptBack(content, 4);
    }
}
